﻿using System;
using NUnit.Framework;

namespace QuickBencher.Test
{
  [TestFixture]
    public class MeasurementTests
    {
        [Test]
        public void Should_format_properly()
        {
            var measurement = new Measurement { 
                UserTime = 1.166667d, SystemTime = 0.05d, TotalTime = 1.216667d, RealTime = 0.571355 };            
            var measurement2 = new Measurement { 
                UserTime = 11.166667d, SystemTime = 20.05d, TotalTime = 331.216667d, RealTime = 440.571355 };            
            Assert.AreEqual("  1.166667   0.050000   1.216667 (  0.571355)", measurement.ToString());
            Assert.AreEqual(" 11.166667  20.050000 331.216667 (440.571355)", measurement2.ToString());
        }

        [Test]
        public void Should_format_properly_with_label()
        {
            var measurement = new Measurement { 
                Label = "Foo:",
                UserTime = 1.166667d, SystemTime = 0.05d, TotalTime = 1.216667d, RealTime = 0.571355 };
            Assert.AreEqual("Foo:        1.166667   0.050000   1.216667 (  0.571355)", measurement.ToString());
        }

        [Test]
        public void Measurement_header_should_look_like_this___()
        {
            Assert.AreEqual("                user     system      total        real", Measurement.GetHeader(Measurement.Header.UsingLabels));
        }

        [Test]
        public void Should_adjust_label_length_is_specified()
        {
            var measurement = new Measurement(20)
            {
                Label = "Foo:",
                UserTime = 1.166667d,
                SystemTime = 0.05d,
                TotalTime = 1.216667d,
                RealTime = 0.571355
            };
            Assert.AreEqual("Foo:                  1.166667   0.050000   1.216667 (  0.571355)", measurement.ToString());
        }

        [Test]
        public void Should_adjust_header_if_label_length_is_specified()
        {
            Assert.AreEqual("           user     system      total        real", Measurement.GetHeader(Measurement.Header.UsingLabelsWidthWidth(5)));
        }
    }
}
